﻿package plugin.superstore.game
{
    import com.core.*;
    import flash.external.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.store.*;
    import plugin.superstore.*;
    import uiresource.store.*;
    import view.uilt.*;

    public class ShopGame extends ExchangeUI
    {
        public var showType:int = 2;
        private var _instance:ExchangeShop;
        private var _selectRoot:int = 0;
        private var _scList:ShopList;
        private var _moneyArr:Array;

        public function ShopGame(param1:ExchangeShop)
        {
            this._instance = param1;
            return;
        }// end function

        override protected function initializeView() : void
        {
            StoreSender._1getStoreInfo();
            var _loc_1:* = Control.create(StoreControl, this);
            ModelProxy.addObserver("store", _loc_1);
            this.initEvent();
            return;
        }// end function

        public function init() : void
        {
            switch(this.showType)
            {
                case 2:
                {
                    shangdian.text = "寻宝积分兑换";
                    break;
                }
                case 3:
                {
                    shangdian.text = "行会贡献兑换";
                    break;
                }
                default:
                {
                    break;
                }
            }
            var _loc_1:* = ConfigDictionary.data.superStore;
            var _loc_2:* = _loc_1[this.showType];
            var _loc_3:* = _loc_2.labels.split("#");
            var _loc_4:* = _loc_2.types.split("#");
            var _loc_5:Array = [];
            var _loc_6:int = 0;
            while (_loc_6 < _loc_3.length)
            {
                
                _loc_5.push({label:_loc_3[_loc_6], type:_loc_4[_loc_6]});
                _loc_6++;
            }
            list_root.array = _loc_5;
            list_root.renderHandler = new Handler(this.rootRender);
            this._moneyArr = [];
            if (_loc_2.moneyType)
            {
                this._moneyArr = _loc_2.moneyType.split("#");
            }
            this.showMsg();
            return;
        }// end function

        private function showMsg() : void
        {
            var _loc_3:int = 0;
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            var _loc_1:Array = [];
            var _loc_2:* = ConfigDictionary.data.item;
            for each (_loc_3 in this._moneyArr)
            {
                
                _loc_4 = _loc_2[_loc_3];
                _loc_5 = this.getMoneyMsg(_loc_3);
                _loc_1.push({txt_type:_loc_4.name + ":", img_type:_loc_5.url, txt_count:_loc_5.count});
            }
            list_money.array = _loc_1;
            list_money.renderHandler = new Handler(this.moneyRender);
            return;
        }// end function

        private function moneyRender(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Label = null;
            var _loc_5:Image = null;
            var _loc_6:Label = null;
            if (param2 < list_money.length)
            {
                _loc_3 = param1.dataSource;
                _loc_4 = param1.getChildByName("txt_type") as Label;
                _loc_4.text = _loc_3.txt_type;
                _loc_5 = param1.getChildByName("img_type") as Image;
                _loc_5.url = _loc_3.img_type;
                _loc_6 = param1.getChildByName("txt_count") as Label;
                _loc_6.text = _loc_3.txt_count;
                _loc_5.x = _loc_4.x + _loc_4.width;
                _loc_6.x = _loc_5.x + _loc_5.width;
            }
            return;
        }// end function

        private function recharge() : void
        {
            if (!ItemUilt.canpay)
            {
                ModelProxy.change("movetips", "error", "功能尚未开放，敬请期待");
                return;
            }
            ExternalInterface.call("topay");
            return;
        }// end function

        private function rootRender(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Button = null;
            if (param2 < list_root.length)
            {
                _loc_3 = param1.dataSource;
                _loc_4 = param1.getChildByName("btn") as Button;
                _loc_4.label = _loc_3.label;
                if (param2 == this._selectRoot)
                {
                    _loc_4.selected = true;
                    if (!this._scList)
                    {
                        this._scList = new ShopList();
                        this.addChild(this._scList);
                    }
                    this._scList.show(this.showType, _loc_3.type);
                }
                _loc_4.clickHandler = new Handler(this.rootClick, [param2]);
            }
            return;
        }// end function

        private function rootClick(param1:int) : void
        {
            this.setSelect(list_root, this._selectRoot, false);
            this.setSelect(list_root, param1, true);
            this._selectRoot = param1;
            this._scList.show(this.showType, list_root.array[param1].type);
            return;
        }// end function

        private function setSelect(param1:List, param2:int, param3:Boolean) : void
        {
            var _loc_4:* = param1.getCell(param2);
            var _loc_5:* = param1.getCell(param2).getChildByName("btn") as Button;
            (param1.getCell(param2).getChildByName("btn") as Button).selected = param3;
            return;
        }// end function

        private function initEvent() : void
        {
            box_base.btn_close.clickHandler = new Handler(this._instance.close);
            return;
        }// end function

        public function update(param1:int, param2:Object) : void
        {
            switch(param1)
            {
                case StorePublic._1INITSTORE:
                {
                    this.init();
                    break;
                }
                case StorePublic._2REFRESH:
                {
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function getMoneyMsg(param1:int) : Object
        {
            var _loc_2:String = null;
            var _loc_3:int = 0;
            switch(param1)
            {
                case 3:
                {
                    _loc_2 = "png.common.cs2_yuanbao";
                    _loc_3 = UserData.getBagData("money");
                    break;
                }
                case 6:
                {
                    _loc_2 = "png.common.cs2_jinbi";
                    _loc_3 = UserData.getBagData("gold");
                    break;
                }
                case 1:
                {
                    _loc_2 = "png.common.bgold";
                    _loc_3 = UserData.getBagData("bgold");
                    break;
                }
                case 2:
                {
                    _loc_2 = "png.common.cs2_qian";
                    _loc_3 = UserData.getBagData("bonus");
                    break;
                }
                case 15:
                {
                    _loc_2 = "png.common.jifen";
                    _loc_3 = UserData.getBagData("jifen");
                    break;
                }
                default:
                {
                    _loc_2 = "png.common.jifen";
                    break;
                    break;
                }
            }
            return {url:_loc_2, count:_loc_3};
        }// end function

    }
}
